package org.tis.tools.senior.module.developer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.senior.module.developer.entity.SWorkitemSupplement;
import org.tis.tools.senior.module.developer.service.ISWorkitemSupplementService;

import javax.validation.constraints.NotBlank;

/**
 * sWorkitemSupplement的Controller类
 * 
 * @author Auto Generate Tools
 * @date 2018/09/14
 */
@RestController
@RequestMapping("/sWorkitemSupplement")
public class SWorkitemSupplementController extends BaseController<SWorkitemSupplement>  {

    @Autowired
    private ISWorkitemSupplementService sWorkitemSupplementService;

    @PostMapping("/add")
    public ResultVO add(@RequestBody @Validated SWorkitemSupplement sWorkitemSupplement) {
        sWorkitemSupplementService.insert(sWorkitemSupplement);
        return ResultVO.success("新增成功！");
    }
    
    @PutMapping
    public ResultVO update(@RequestBody @Validated SWorkitemSupplement sWorkitemSupplement) {
        sWorkitemSupplementService.updateById(sWorkitemSupplement);
        return ResultVO.success("修改成功！");
    }
    
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") String id) {
        sWorkitemSupplementService.deleteById(id);
        return ResultVO.success("删除成功");
    }
    
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") String id) {
        SWorkitemSupplement sWorkitemSupplement = sWorkitemSupplementService.selectById(id);
        if (sWorkitemSupplementService == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", sWorkitemSupplement);
    }
    
    @PostMapping("/list")
    public ResultVO list(@RequestBody @Validated SmartPage<SWorkitemSupplement> page) {
        return  ResultVO.success("查询成功", sWorkitemSupplementService.selectPage(getPage(page), getCondition(page)));
    }
    
}

